//
//  MainViewController.m
//  oc_demo
//
//  Created by haigui on 2021/8/5.
//

#import "MainViewController.h"
#import "MMTableView.h"
#import "MenuInfo.h"
#import "ScanQRCodeViewController.h"
#import "UserModel.h"
#import "ViewMoveViewController.h"
#import "WKViewController.h"
#import "AFNDownloadImgViewController.h"
#import "KeybordViewController.h"
#import "CycleDelayViewController.h"
#import "LianliankanViewController.h"
#import "RoundViewController.h"
@interface MainViewController ()<UITableViewDelegate, UITableViewDataSource>

/**
 数据源
 */
@property (nonatomic, strong) NSMutableArray *arrMenuData;
@property (nonatomic, strong) MMTableView *tableView;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"demo";
    
    UIBarButtonItem *shareBarButton = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"share_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(shareBarButtonClick:)];
    self.navigationItem.rightBarButtonItem = shareBarButton;
    
    UserModel *userModel = [[UserModel alloc]init];
    userModel.userId = 1;
    userModel.token_type = @"Bearer";
    userModel.access_token = @"TUTNC4SWV9V0NZY9EDET7W6KWDCO5XDN";
    [UserModel archive:userModel];
    
    _arrMenuData = [self getMenuData];
    
    [self.view addSubview:self.tableView];
}

#pragma mark - --------------代理方法--------------
#pragma mark -- UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arrMenuData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font = [GlobalFile fontOfSize15];
        cell.textLabel.textColor = [GlobalFile textColorWithDefaultBlack];
    }
    MenuInfo *menuInfo = _arrMenuData[indexPath.row];
    cell.textLabel.text = menuInfo.menuName;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MenuInfo *menuInfo = _arrMenuData[indexPath.row];
    switch (menuInfo.menuID) {
        case 0:{
            ScanQRCodeViewController *vc = [[ScanQRCodeViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:{
            ViewMoveViewController *vc = [[ViewMoveViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:{
            WKViewController *vc = [[WKViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:{
            AFNDownloadImgViewController *vc = [[AFNDownloadImgViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:{
            KeybordViewController *vc = [[KeybordViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 5:{
            CycleDelayViewController *vc = [[CycleDelayViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 6:{
            LianliankanViewController *vc = [[LianliankanViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 7:{
            RoundViewController *vc = [[RoundViewController alloc]init];
            vc.navigationItem.title = menuInfo.menuName;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}
#pragma mark - --------------自定义方法--------------
//获取整理好的数据
- (NSMutableArray *)getMenuData{
    MenuInfo *menuInfo0 = [[MenuInfo alloc]initWithMenuID:0 menuName:@"扫一扫"];
    MenuInfo *menuInfo1 = [[MenuInfo alloc]initWithMenuID:1 menuName:@"手势：view随手指移动"];
    MenuInfo *menuInfo2 = [[MenuInfo alloc]initWithMenuID:2 menuName:@"WKWebView"];
    MenuInfo *menuInfo3 = [[MenuInfo alloc]initWithMenuID:3 menuName:@"AFN下载图片覆盖项目包中的图片"];
    MenuInfo *menuInfo4 = [[MenuInfo alloc]initWithMenuID:4 menuName:@"键盘弹出"];
    MenuInfo *menuInfo5 = [[MenuInfo alloc]initWithMenuID:5 menuName:@"循环的延迟执行"];
    MenuInfo *menuInfo6 = [[MenuInfo alloc]initWithMenuID:6 menuName:@"连连看"];
    MenuInfo *menuInfo7 = [[MenuInfo alloc]initWithMenuID:7 menuName:@"测试圆角"];
    return [NSMutableArray arrayWithObjects:menuInfo0, menuInfo1, menuInfo2, menuInfo3, menuInfo4, menuInfo5, menuInfo6, menuInfo7, nil];
}

#pragma mark - --------------Getter方法--------------
- (MMTableView *)tableView{
    if (!_tableView) {
        _tableView = [[MMTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationBarHeight) style:UITableViewStylePlain dataSource:self delegate:self];
    }
    return _tableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
